package com.xiexin.setmeals.service.impl;

import com.xiexin.setmeals.domain.Setmeal;
import com.xiexin.setmeals.domain.SetmealGroup;
import com.xiexin.setmeals.mapper.SetmealGroupMapper;
import com.xiexin.setmeals.mapper.SetmealMapper;
import com.xiexin.setmeals.service.ISetmealService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 套餐信息Service业务层处理
 *
 * @author xiexin
 * @date 2022-03-25
 */
@Service
public class SetmealServiceImpl implements ISetmealService {
    @Resource
    private SetmealMapper setmealMapper;
    @Resource
    private SetmealGroupMapper setmealGroupMapper;

    /**
     * 查询套餐信息
     *
     * @param id 套餐信息主键
     * @return 套餐信息
     */
    @Override
    public Setmeal selectSetmealById(Long id) {
        return setmealMapper.selectSetmealById(id);
    }

    /**
     * 查询套餐信息列表
     *
     * @param setmeal 套餐信息
     * @return 套餐信息
     */
    @Override
    public List<Setmeal> selectSetmealList(Setmeal setmeal) {
        return setmealMapper.selectSetmealList(setmeal);
    }

    /**
     * 新增套餐信息
     *
     * @param setmeal 套餐信息
     * @return 结果
     */
    @Override
    public int insertSetmeal(Setmeal setmeal) {
        return setmealMapper.insertSetmeal(setmeal);
    }

    /**
     * 修改套餐信息
     *
     * @param setmeal 套餐信息
     * @return 结果
     */
    @Override
    public int updateSetmeal(Setmeal setmeal) {
        return setmealMapper.updateSetmeal(setmeal);
    }

    /**
     * 批量删除套餐信息
     *
     * @param ids 需要删除的套餐信息主键
     * @return 结果
     */
    @Override
    public int deleteSetmealByIds(Long[] ids) {
        return setmealMapper.deleteSetmealByIds(ids);
    }

    /**
     * 删除套餐信息信息
     *
     * @param id 套餐信息主键
     * @return 结果
     */
    @Override
    public int deleteSetmealById(Long id) {
        return setmealMapper.deleteSetmealById(id);
    }

    @Override
    public int insertSetmeal(Setmeal setmeal, List groupIds) {
        setmealMapper.insertSetmeal(setmeal);
        System.out.println("groupIds"+groupIds);
        groupIds.forEach(l -> {
            SetmealGroup setmealGroup = new SetmealGroup();
            setmealGroup.setGroupId(Long.parseLong(l + ""));
            setmealGroup.setSetmealId(setmeal.getId());
            setmealGroupMapper.insertSetmealGroup(setmealGroup);
        });
        return 1;
    }
}
